import 'package:get/get.dart';
import 'package:im_flutter_sdk/im_flutter_sdk.dart';
import 'package:industry_net/base/common/util.dart';
import 'package:industry_net/pages/msg/im/pages/chat/chat_page.dart';
import '../models/chat_list.dart';

import 'index.dart';

class ChatListController extends GetxController {
  ChatListController();

  final state = ChatListState();

  // tap
  void handleTap(int index) {
    Get.snackbar(
      "标题",
      "消息",
    );
  }

  void actionCellClick(ChatListModel md) async {
    // Get.toNamed(RouterPath.chat);
    EMConversation? con = await EMClient.getInstance.chatManager
        .getConversation('123', EMConversationType.Chat);
    Get.to(() => ChatPage('小明', con!));
  }

  void getChatData() {
    state.list = List.generate(10, (index) => ChatListModel());
    update();
  }

  /// 在 widget 内存中分配后立即调用。
  @override
  void onInit() {
    super.onInit();
  }

  /// 在 onInit() 之后调用 1 帧。这是进入的理想场所
  @override
  void onReady() {
    getChatData();
    super.onReady();
  }

  /// 在 [onDelete] 方法之前调用。
  @override
  void onClose() {
    super.onClose();
  }

  /// dispose 释放内存
  @override
  void dispose() {
    super.dispose();
  }
}
